from base.util import BoxDriver,BasePage
from time import sleep
import yaml

class LoginPage(BasePage):

    # def __init__(self,driver):
    #     super().__init__(driver)

    def login(self,username='admin',password='123456'):
        '''登陆功能用例'''
        driver = self.driver

        # 加载数据文件
        config = self.get_yaml(r'selenium\ranzhi\data\config.yaml')
            
        # 定位信息
        ACCOUNT = config['LoginPage']['ACCOUNT']
        PASSWORD = config['LoginPage']['PASSWORD']
        SUBMIT = config['LoginPage']['SUBMIT']

        # 登陆
        driver.input(ACCOUNT,username)
        driver.input(PASSWORD,password)
        driver.click(SUBMIT)
        sleep(1)

    def confirm(self):
        # 点击 确认
        self.driver.click('x,/html/body/div[2]/div/div/div[2]/button')

    def exit(self):
        # 点击 签退
        # self.driver.click('x,//*[contains(text(),"签退")]')
        self.driver.click('l,签退')

    def get_realname(self):
        # 获取真名
        return self.driver.locate_element('x,//*[@id="mainNavbar"]/div/ul[1]/li/a').text

    def get_msg(self):
        # 获取提示信息
        return self.driver.locate_element('x,/html/body/div[2]/div/div/div[1]/div').text

if __name__ == "__main__":
    LoginPage(BoxDriver()).login()